package org.suk.dp.composite;

import java.util.LinkedList;
import java.util.List;

/**
 * Description: 组合类<br/>
 * @version V1.0  2017/6/21 13:35  by 石冬冬(dongdong.shi@ucarinc.com) - Heil Hitler
 */
public class Composite extends Component {
    private List<Component> children = new LinkedList<Component>();
    public Composite(String name) {
        super(name);
    }

    @Override
    void add(Component component) {
        this.children.add(component);
    }

    @Override
    void remove(Component component) {
        this.children.remove(component);
    }

    @Override
    void display(int depth) {
        System.out.println(new StringBuilder("-").append(depth).append(this.name).toString());
        for(Component c : this.children){
            c.display(depth + 2);
        }
    }
}
